package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "C端-套餐接口")
public class UserSetmealController {
    @Autowired
    private SetmealService setmealService;
    /**
     * 根据分类查询套餐
     *
     * @param categoryId 分类ID
     */
    @GetMapping("/list")
    @ApiOperation("根据分类查询套餐")
    @Cacheable(cacheNames = "SetmealCache",key = "#categoryId")//redis中key为userCache::categoryId
    public Result<List<SetmealVO>> list(Long categoryId) {
        log.info("查询分类套餐ID：{}", categoryId);
        //创建查询对象
        Setmeal setmeal = Setmeal.builder()
                .categoryId(categoryId)
                .status(StatusConstant.ENABLE)
                .build();
        List<SetmealVO> list = setmealService.list(setmeal);
        return Result.success(list);
    }
    /**
     * 根据ID查询套餐和套餐菜品信息
     *
     * @param id 套餐ID
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据ID查询套餐和套餐菜品信息")
    @Cacheable(cacheNames = "setmealDishCache",key = "#id")
    public Result<List<DishItemVO>> getByIdWithDish(@PathVariable Long id) {
        log.info("查询ID：{}", id);
        List<DishItemVO> dishItemVOList = setmealService.getByIdWithDish(id);
        return Result.success(dishItemVOList);
    }
}
